# _*_ coding: utf-8 _*_
from odoo import models, fields, api


class ProductCategoryAttributeSetting(models.Model):
    _name = "product.category.attribute.setting"
    _description = u"产品属性设定"

    product_category_id = fields.Many2one("product.category", string="Product Category")
    product_attribute_ids = fields.Many2many("product.attribute", string="Product Attribute")

    _sql_constraints = [
        ('category_id', 'unique (product_category_id)', u'已存在相同[产品分类]的记录！'),
    ]

    @api.model
    def get_attributes_by_category(self, category_id):
        setting = self.search([("product_category_id", "=", category_id)])
        return setting.product_attribute_ids
